package com.cjjd.c.feature.mine.message;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.FrameLayout;

import com.cjjd.c.ShareKeys;
import com.cjjd.c.base.BaseSwipeRefreshFragment;
import com.cjjd.c.base.MyBaseAdapter;
import com.cjjd.c.bean.HttpResult;
import com.cjjd.c.bean.ListResult;
import com.cjjd.c.bean.MessageItem;
import com.cjjd.c.http.JsonUtils;
import com.cjjd.c.utils.SharePrefUtil;

import java.util.HashMap;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * ----------------------------------
 * Created by xyd on 2017/8/14.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class MessageFragment extends BaseSwipeRefreshFragment {

    private ListResult<MessageItem> listResult;

    @Override
    public Object getTitleString() {
        return "短消息";
    }

    @Override
    public void responseSuccess(Call<HttpResult> call, Response<HttpResult> response) {
        listResult = (ListResult<MessageItem>) response.body().getData();
        setDataList(listResult.dataList);
    }

    @Override
    protected void initView() {
        super.initView();
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(0, (int) (10 * getResources().getDisplayMetrics().density + 0.5), 0, 0);
        listBase.setLayoutParams(layoutParams);


        listBase.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.e("xyd","postoin " + position + "被点击了");

                SystemMessageDetailActivity.lauch(mContext,listResult.dataList.get(position).uuid);

            }
        });
    }

    private void getSysMessageDetail(String uuid) {

    }

    @Override
    public MyBaseAdapter getAdapter() {
        return new MessageAdapter(mContext);
    }

    @Override
    public Call<HttpResult> getCall() {
        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));
        h1.put("nowPage", PAGE + "");
        h1.put("pageShow", PAGE_SIZE + "");

        return service.getSysMessageList(JsonUtils.convertParam("getSysMessageList", h1));
    }
}
